<%@page import="com.itsm.v17.entity.Prize"%>
<%@page import="java.util.LinkedList"%>
<%@page import="java.util.List"%>
<%@ page pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String message=request.getAttribute("message")+"";
List list=(List)request.getAttribute("list");
if(list==null){list=new LinkedList();}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>奖品管理</title>
<link href="<%=basePath%>css/home.css" type="text/css" rel="stylesheet" />
<script src="<%=basePath%>js/DatePicker/WdatePicker.js" type="text/javascript"></script>
<link href="<%=basePath%>js/DatePicker/skin/WdatePicker.css" rel="stylesheet" type="text/css">
<script src="<%=basePath%>itsm/js/ajax.js"></script>
<script src="<%=basePath%>itsm/js/ajax.form.js"></script>
<script src="<%=basePath%>itsm/js/formValidate.js"></script>
<script src="<%=basePath%>itsm/js/select.js"></script>
<script src="<%=basePath%>itsm/js/reSet.js"></script>
<style>
.tableblue00 td{
padding:5px;
}
</style>
</head>
<body style="padding:5px;margin:0px;">
<table width="100%" cellspacing="1" cellpadding="0" border="0" bgcolor="#D6E6F4" class="tableblue00">
                            <tbody>
                            <tr class="bbzxbg2">
                              <td colspan=3 >
                              	&nbsp; &nbsp;
                              	 <a class="actionbutton"  href='<%=path%>/itsm17/prize/activity/admin'  class="menudiv" style="margin-right: 10px;color:white;">返回</a>
                              	 &nbsp; &nbsp;
                              	 <a class="actionbutton"  href='javascript:;' onclick="create()" class="menudiv" style="margin-right: 10px;">新建</a>
                              	 &nbsp;&nbsp;
                              </td>
                            </tr></tbody>
          </table> <br/>
                     
 <table width="100%" cellspacing="1" cellpadding="0" border="0" bgcolor="#D6E6F4" class="tableblue00">
   <tbody>
   <tr class="bbzxbg2">
                <td width="20%">奖品名称</td>
                <td align="left">中奖权重</td>
                <td align="left">奖品数量</td>
                <td align="left">已抽数量</td>
                <td align="left">剩余数量</td>
                <td align="left">邮箱空间</td>
                <td align="left">下一个中奖</td>
                <td align="left">操作</td>
         </tr>
   <%
   int all=0,used=0;
   		for(int i=0;i<list.size();i++)
   		{
   			Prize prize=(Prize)list.get(i);
   			all=all+prize.getNum();
   			used=used+prize.getUsedNum();
   			//System.out.println(prize.getName()+",usedCount="+prize.getUsedNum());
   			%>
   				<tr class="bbzxbg2">
                <td width="20%"><%=prize.getName()%></td>
                <td align="left"><%=prize.getPercent()%></td>
                <td align="left"><%=prize.getNum()%></td>
                <td align="left"><%=prize.getUsedNum()%></td>
                <td align="left"><%=(prize.getNum()-prize.getUsedNum())%></td>
                <td align="left"><%=prize.getSpace()%></td>
                <td align="left"><%if("0".equals(prize.getNextChoosed())){out.print("否");}else{out.print("是");}%></td>
                <td align="left">
                	<a href="javascript:;" onclick="edit('<%=prize.getId()%>','<%=prize.getPid()%>','<%=prize.getName()%>','<%=prize.getPercent()%>','<%=prize.getNum()%>','<%=prize.getSpace()%>','<%=prize.getNextChoosed()%>')">编辑</a>
                	&nbsp;&nbsp;
                	<a href="javascript:;" onclick="deletes('<%=prize.getId()%>','<%=prize.getName()%>',this)">删除</a>
                	&nbsp;&nbsp;
                	</td>
         </tr>
   			<%
   		}
   %>
          <tr class="bbzxbg2">
                <td colspan=8 align="left">总数<%=all%> &nbsp;&nbsp;已抽<%=used%> &nbsp;&nbsp; 剩余<%=(all-used)%> &nbsp;&nbsp;&nbsp;<%=message%></td>
         </tr>               
 </tbody>
</table>      <br/>               
                     
  <table width="100%" cellspacing="1" cellpadding="0" border="0" bgcolor="#D6E6F4" class="tableblue00" id="datafrom" style="display:none;" >
                            <tbody>
                            <tr class="bbzxbg2">
                              <td colspan=3 >
                              	<input type="hidden" name="id" id="id" />
                              	<input type="hidden" name="pid" id="pid" />
                              	 奖品名称： <input type="text" name="name" id="name" value=""  
                              	 require=true min=1 message="奖品名称必须填写" />
                              	 &nbsp; &nbsp; &nbsp; &nbsp;
                              	 中奖概率： <input type="text" name="percent" id="percent" value=""   
                              	 require=true min=1 message="中奖概率必须填写" />
                              	 &nbsp; &nbsp; &nbsp; &nbsp;
                              	 奖品数量： <input type="text" name="num" id="num" value="" 
                              	 require=true min=1 message="奖品数量必须填写" />
                              	 &nbsp; &nbsp; &nbsp; &nbsp;
                              	 邮箱空间： <input type="text" name="space" id="space" value="" 
                              	 require=true min=1 message="邮箱空间必须填写" />
                              	 &nbsp; &nbsp; &nbsp; &nbsp;   
                              	  下一个中奖:<select id="nextChoosed" name="nextChoosed" >
                              	 	<option value="0">否</option>
                              	 	<option value="1">是</option>
                              	 </select>
                              	  &nbsp; &nbsp; &nbsp; &nbsp;                             	 
                              	 <a class="actionbutton"  href='javascript:;' onclick="save()" class="menudiv" style="margin-right: 10px;">保存</a>
                              	 &nbsp;&nbsp;
                              	 <span id="message"></span>
                              </td>
                            </tr></tbody>
          </table>
                     <br/>      
<script>
var pid="<%=request.getParameter("pid")%>";
function create()
{
	get("message").innerHTML='';
	reSet("datafrom");
	show("datafrom");
	get("pid").value=pid;
}
function save()
{
	get("message").innerHTML='';
	if(!formValidate("datafrom")){return;}
	get("message").innerHTML='正在提交...';	
	new ajaxForm({'url':'<%=path%>/itsm17/prize/save','form':'datafrom','success':function(data)
		{
			var json=toJson(data);
			if(json.result)
			{
				location.reload();
			}else
			{
				get("message").innerHTML='<font color=red>'+json.message+'</font>';	
			}
		}});	
}
function edit(id,pid,name,percent,num,space,nextChoosed)
{
	get("message").innerHTML='';
	show("datafrom");
	get("id").value=id;
	get("pid").value=pid;
	get("name").value=name;
	get("percent").value=percent;
	get("num").value=num;
	get("space").value=space;
	setSelectSelected("nextChoosed",nextChoosed);
}
var isDelete=false;
function deletes(id,name,obj)
{
	if(isDelete){return;}
	if(confirm("确定删除?"+name))
	{
		isDelete=true;
		obj.innerHTML="正在删除...";
		new ajax({'url':'<%=path%>/itsm17/prize/delete','params':'id='+id,'success':function(data)
			{
				isDelete=false;
				var json=toJson(data);
				if(json.result)
				{
					location.reload();
				}else
				{
					alert(json.message);	
				}
			}});
	}
}
</script>
</body>
</html>